<template>
  <view class="box"@click.stop="showchangetype=false">
    <view class="box-header">
      <view class="head-box">
        <shopro-navbar back-icon-color="#fff" :background="{}">
          <view class="u-flex-1 u-flex  u-row-center u-col-center" slot="content">
            <view style="color:#ffffff">{{ title }}</view>
          </view>
        </shopro-navbar>
      </view>
      <view class="head-userInfo">
        <view class="head-userInfo-photo">
          <image :src="pinkInfoList.user.avatar" mode=""></image>
        </view>
        <view class="head-userInfo-user">
          <view class="head-userInfo-name">
            {{pinkInfoList.user.nickname}}
          </view>
          <view class="head-userInfo-msg">
            开通多米会员，尽享更多权益
          </view>
        </view>
      </view>
    </view>
    <view class="card-tg">
      <view class="card-top">
        <view class="coutdowm">
          <view class="pinkList-title-right" v-if="pinkInfoList.pink&&pinkInfoList.pink.times > '0'">
            倒计时：
            <u-count-down :timestamp="pinkInfoList.pink.times" :is_active_time="false" :show-days="false" color="#FFF"
                          bg-color="#000" @end="countDown(pinkInfoList.pink.vip_pink_id,1)">
            </u-count-down>
          </view>
          <view class="pinkList-title-right" v-else>
            <view class="pinkList-title-right-btn1">
              砍价已结束
            </view>
          </view>
        </view>
        <view class="card-top-img" v-if="pinkInfoList.list.length>0&&title=='砍价详情'">
          <view class="changetype">
            <view class="changename" @click.stop="pinkInfoList.pink.times>0?showchangetype=true:kong()">{{cardLisrArr[pinkInfoList.pink.vip_id-1].name}}</view>
            <u-icon name="arrow-down" @click="pinkInfoList.pink.times>0?showchangetype=true:kong()"></u-icon>
            <view v-if="showchangetype" class="changcontent">
              <view class="content-items" v-for="(items ,indexs) in cardLisrArr" :keys="indexs">
                <view class="content-items-name" @click="changtypes(items)">{{items.name}}</view>
              </view>
            </view>

          </view>
          <view class="card-tg-item" v-for="(item,index) in pinkInfoList.list" :key="index">
            <image class="card-tg-items" mode="aspectFit" :src="item.avatar?item.avatar:'https://duomi.bigchun.com/imgs/help.png'">
            </image>
          </view>
        </view>
      </view>
    </view>
    <!--  -->
    <view class="pinkList"  v-if="pinkInfoList.pink&&pinkInfoList.list.length>0">
      <view class="pinkList-title">
        <view class="pinkList-list-title">
          <view class="pinkList-list-title-item" :class="activeTitle=='1'?'active-title':''" @click="activeTitle=1"> 砍价记录</view>
          <view class="pinkList-list-title-item" :class="activeTitle=='2'?'active-title':''" @click="activeTitle=2"> 砍价规则</view>
        </view>
        <view class="pinkList-title-left" v-if="activeTitle=='1'">
          <view style="display: flex;justify-content: space-between;align-items: center;width: 100%;" v-for="(item,index) in pinkInfoList.list" :key="item.id"  v-if="item.is_main!=1&&item.createtime">
            <view class="name_content">
              <image :src="item.avatar?item.avatar:'https://duomi.bigchun.com/images/huixiang1.png'" mode="">
              </image>
              <view class="pinkList-title-left-cardType">
                {{item.nickname}} 帮忙砍价
              </view>
            </view>
            <view class="pinkList-title-left-cardType">
              {{item.createtime}}
            </view>
          </view>
          <view class="nodata" v-if="(title=='拼团详情'&&pinkInfoList.list.length==0)||(title=='砍价详情'&&pinkInfoList.list.length==1)">暂无邀请记录~</view>
        </view>
        <view class="pinkList-title-left" :key="item.id" v-if="activeTitle=='2'">
          <view class="guize">
            <view class="footer-oneTitle">
              <view class="guize-shuoming">
                <view class="footer-Title-msg">
                  如何成为免费会员：发出助力链接，邀请他人助力，可免费成为会员。
                </view>
              </view>
              <view class="guize-item">
                <view class="footer-oneTitle-msg">
                  <view class="footer-oneTitle-msg-row footer-oneTitle-title">
                    <view class="footer-oneTitle-msg-col">会员卡类型</view>
                    <view class="footer-oneTitle-msg-col">需邀请助力人数</view>
                  </view>
                  <view class="footer-oneTitle-msg-row" v-for="(item_huiyuan, index_huiyuan) in cardLisrArr">
                    <view class="footer-oneTitle-msg-col title-cols">
                      {{ item_huiyuan.name }}</view>
                    <view class="footer-oneTitle-msg-col">{{ item_huiyuan.people || 0 }}</view>
                  </view>
                </view>
              </view>
              <view class="guize-shuoming">
                <view class="footer-Title-msg">
                  ① 受邀人如何助力：参与助力的人只需进入程序平台，点击“为他助力”即可，无需支付任何费用。
                </view>
                <view class="footer-Title-msg">
                  ② 有效时间：发出助力链接后24小时内有效，如有效时间内未完成助力，可继续发出链接，邀约助力，每次发出邀约的链接有效时间为24小时。
                </view>
              </view>
            </view>
          </view>

        </view>
      </view>
    </view>
    <u-modal v-model="fxShow" :show-cancel-button="true" :content="content">
      <view slot="confirm-button">
        <button open-type="share"
                style="height: 110rpx;display: flex;justify-content: center;align-items: center;background: none;font-size: 32rpx;">发给微信好友</button>
      </view>
    </u-modal>
  </view>
</template>

<script>
import {
  mapMutations,
  mapActions,
  mapState,
  mapGetters
} from 'vuex'
export default {
  data() {
    return {
      activeTitle:1,
      title:'砍价详情',
      fxcontent: '',
      fxShow: false,
      tgIndex: 0,
      cardLisrArr: [],
      vip_id: '',
      typeId: '',
      pinkInfoList: {
        data: {
          list: []
        }
      },
      isOpen: false,
      shareOrder: {},
      price: 0,
      content: '',
      nickname: '',
      screnVipShareObj: null,
      shareLinkId: 0,
      typeShareOpen: 1,
      fxPinkId: 0,
      fxPrice: 0,
      vip_pink_Id:'',
      typeTitle:'2',
      showchangetype:false
    }
  },
  onShow() {
  },
  onLoad(options) {
    this.title='砍价详情'
    this.vip_pink_Id = this.$Route.query.id
    this.typeTitle = this.$Route.query.typeTitle
    let screnVipShareObj = uni.getStorageSync('screnVipShareObj')
    if (screnVipShareObj) {
      if (screnVipShareObj.userId == uni.getStorageSync('userInfo').id) return uni.removeStorageSync('screnVipShareObj')
      this.screnVipShareObj = screnVipShareObj
      this.shareOpenUserDetail()
      uni.removeStorageSync('screnVipShareObj')
    }
    this.getPinkInfoList()
    let timer = null;
    clearInterval(timer);
    if(  this.typeTitle == 1){
      timer = setInterval(()=>{
        this.getPinkInfoList();
        if(!this.pinkInfoList.pink||this.pinkInfoList.pink.times<=0){
          clearInterval(timer)
        }
      },10000)
    }
  },
  computed: {
    ...mapGetters(['initStore']),
  },
  methods: {
    kong(){// 写的默认空事件  不可删除
    },
    //切换砍价类型
    changtypes(items){
      let self = this;
      uni.showModal({
        title: ' ',
        content: '是否确认切换成'+items.name+'？',
        cancelText: "取消",
        confirmText: "确定",
        confirmColor: '#FC5351',
        cancelColor: '#000',
        success: function(res) {
          if (res.confirm) {
            const data = {
              vip_id:items.id,
              vip_help_id:self.vip_pink_Id
            }
            self.$https('vip.tabHelp', data).then(res => {
              if(res.code=='1'){
                self.$u.toast('切换成功');
                self.showchangetype = false
              }
            })
          } else if (res.cancel) {
            self.showchangetype = false
          }
        }
      });
    },
    countDown(id, type) {
      const data = {
        id,
        type
      }
      this.$https('vip.updateOrder', data).then(res => {
        this.getPinkInfoList()
      })
    },
    // 删除团购
    pinkDelete(item) {
      let self = this
      uni.showModal({
        title: ' ',
        content: '是否确认删除？',
        cancelText: "取消",
        confirmText: "确定",
        confirmColor: '#FC5351',
        cancelColor: '#000',
        success: function(res) {
          if (res.confirm) {
            const data = {
              id: id
            }
            self.$https('vip.delPink', data).then(res => {
              self.$u.toast('删除成功');
              self.getPinkInfoList()
            })
          } else if (res.cancel) {

          }
        }
      });

    },
    helpAgain(item) {
      this.content = `快去邀请微信好友 帮您砍价吧`
      this.fxShow = true
      this.shareOrder = item.pink ? item.pink:{}
    },
    // 通过链接 获取团长信息昵称
    shareOpenUserDetail() {
      let {
        vip_help_id,
        shareVipType
      } = this.screnVipShareObj
      this.$https('vip.orderAvatar', {
        id: vip_help_id,
        type: shareVipType
      }).then(res => {
        this.helpShow = true
        if (res.code) {
          this.avatar = res.data.user.avatar
          this.nickname = res.data.user.nickname
          this.fxPinkId = res.data.vip.id
          this.fxPrice = res.data.vip.price
        }

      })
    },
    closeHelpChange() {
      this.helpShow = false
    },
    ...mapActions(['getUserInfo', 'showAuthModal', 'logout']),
    //获取vip列表
    getVipList() {
      this.$https('vip.vipList').then(res => {
        this.cardLisrArr = res.data
        this.vip_id = this.cardLisrArr[this.pinkInfoList.pink.vip_id-1].id
        this.price = this.cardLisrArr[this.pinkInfoList.pink.vip_id-1].price
      })
    },
    // 查看团购人员参与及助力人员
    getPinkInfoList() {
      let url='vip.helplists_detail'
      this.$https(url,{
        token:uni.getStorageSync("token"),
        id:this.vip_pink_Id
      }).then(resPinkInfo => {
        this.pinkInfoList = resPinkInfo.data;
        this.getVipList()
      })
    },
  },

  onShareAppMessage() {
    let screnObj = {}
    let path = null
    screnObj.typeTitle = this.typeTitle
    if (this.shareOrder.vip_help_id) screnObj = {
      vip_help_id: this.shareOrder.vip_help_id,
      shareVipType: 2,
      userId: uni.getStorageSync('userInfo').id
    }
    path = `pages/index/membeRecharge?${screnObj.vip_help_id ? 'screnVipShareObj=' + JSON.stringify(screnObj) : ''}&userBindId=${screnObj.userId}`
    return {
      path,
      imageUrl: 'https://duomi.bigchun.com/imgs/vip/shareBg.jpg',
      title: this.title=='拼团详情'?'快来一起拼团吧~':'快来帮我助力吧~'
    }
  },

}
</script>

<style lang="less" scoped>
page{
  background: #F8F8F8!important;
}
.helpShowClass {
  text-align: center;
  width: 638rpx;
  min-height: 300rpx;
  padding: 0 0 78rpx;
  background: white;
  border-radius: 16rpx;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 30%;

  .help-show-close {
    position: absolute;
    right: 26rpx;
    top: 26rpx;
  }

  image {
    width: 124rpx;
    height: 124rpx;
    display: block;
    border-radius: 50%;
    z-index: 99999;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  &-tite {
    font-size: 36rpx;
    font-weight: bold;
    color: #333333;
    margin-top: 72rpx;
    margin-bottom: 40rpx;

  }

  &-content {
    font-size: 32rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #999999;
    margin-bottom: 50rpx;
  }

  &-btn1 {
    margin: 0 44rpx;
    text-align: center;
    line-height: 88rpx;
    border-radius: 16rpx;
    background: linear-gradient(90deg, #FC5351 0%, #FF6E6D 100%);
    color: #fff;
    font-size: 32rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
  }
  &-btn{
    width: 87%;
    margin: 30rpx 44rpx 0;
    text-align: center;
    line-height: 88rpx;
    border-radius: 16rpx;
    background: linear-gradient(90deg, #FC5351 0%, #FF6E6D 100%);
    color: #fff;
    font-size: 32rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
  }
}

.box {
  width: 100%;
  min-height: 100vh;
  background: #FFECCF;
}

.box-header {
  background: url(https://ynkg-yff.oss-cn-hangzhou.aliyuncs.com/temp/1_1665715781852.png) no-repeat;
  background-size: 100% 100%;
  height: 368rpx;
  display: flex;
}

.head-userInfo {
  width: 95%;
  height: 132rpx;
  display: flex;
  margin: 0 auto;
  border-radius: 8rpx 8rpx 0 0;
  background: rgba(255, 255, 255, 0.4);
  align-self: flex-end;
  padding: 24rpx;

  .head-userInfo-photo {
    width: 88rpx;
    height: 88rpx;

    image {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      margin-right: 20rpx;
    }
  }

  .head-userInfo-user {
    display: flex;
    flex-direction: column;
    color: #623808;
    margin-left: 15rpx;

    .head-userInfo-name {
      font-size: 36rpx;
    }

    .head-userInfo-msg {
      font-size: 28rpx;
    }
  }
}

.card-list {
  width: 95%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;

  &-item {
    width: 30%;
    height: 280rpx;
    box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    flex-direction: column;

    image {
      width: 32rpx;
      height: 32rpx;
      margin: 42rpx 0 14rpx 0;
    }

    &-name {
      font-size: 28rpx;
      font-weight: 500;
      color: #623808;
      margin-bottom: 12rpx;
    }

    &-price {
      font-size: 44rpx;
      font-weight: bold;
      color: #623808;
      margin-bottom: 12rpx;
    }

    &-time {
      font-size: 24rpx;
      font-weight: 500;
      color: #999999;
    }
  }
}

.active {
  background: #FCFAEE;
  border: #EAC58E 4rpx solid;
}

.card-tg {
  width: 95%;
  margin: 20rpx auto;
  display: flex;
  justify-content: space-between;

  &-item {
    width: 30%;
    height: 108rpx;
    border-radius: 16rpx;
    opacity: 1;
    color: #666666;
    line-height: 108rpx;
    text-align: center;
  }
}
.pinkList {
  width: 95%;
  margin: 20rpx auto;
  border:0.001rpx solid transparent;
  .pinkList-title{
    margin-bottom: 50rpx;
    .pinkList-list-title{
      background: #FFD69B;
      width: 100%;
      display: flex;
      border-radius: 24rpx 24rpx 0 0;
      padding: 30rpx 20rpx 30rpx;
      font-size: 32rpx;
      font-weight: bold;
      align-items: center;
      .pinkList-list-title-item{
        width: 50%;
        height: 50rpx;
        display: flex;
        justify-content: center;
        border-right:4rpx solid #D3B178 ;
        &:last-child{
          border-right: none;
        }
      }
      .active-title{
        color:#D12D20;
      }
    }
    .pinkList-title-left {
      background:#FFF9EB;
      border: 2rpx solid #E1B978;
      border-top: 0rpx solid #E1B978;
      border-radius: 0px 0px 8px 8px;
      opacity: 1;
      display: flex;
      font-size: 28rpx;
      font-weight: 500;
      color: #333333;
      justify-content: space-between;
      align-items: center;
      padding: 20rpx;
      min-height: 180rpx;
      .nodata{
        display: flex;
        align-items: center;
        height: 100%;
        width: 100%;
        justify-content: center;
      }
      .name_content{
        display: flex;
        align-items: center;
        image {
          width: 80rpx;
          height: 80rpx;
          margin-right: 20rpx;
        }
        .pinkList-title-left-cardType{
          font-size: 28rpx;
          color: #333333;
        }
      }
      .pinkList-title-left-cardType{
        font-size: 24rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        color: #999999;
      }
    }

    .pinkList-list-pinkList {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 20rpx;
      margin-bottom: 28rpx;

      .pinkList-list-pinkList-left {
        display: flex;
        justify-content: center;
        align-items: center;

        image {
          width: 64rpx;
          height: 64rpx;
          border-radius: 50%;
          margin-right: 10rpx;
        }
      }
    }
    //规则样式
    .guize{
      width: 100%;
      .footer-oneTitle{
        width: 100%;
        .guize-item{
          width: 100%;
          margin-bottom: 30rpx;
          .footer-oneTitle-msg{
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-direction: column;
            border-left: 2rpx solid #FCE8C9;
            .footer-oneTitle-msg-row{
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              .footer-oneTitle-msg-col{
                flex: 1;
                border-bottom: 2rpx solid #FCE8C9;
                border-right: 2rpx solid #FCE8C9;
                display: flex;
                justify-content: center;
                align-items: center;
                background: #FFF4DC;
                padding: 20rpx 0;
              }
              .title-cols{
                color: #884D14;
              }
            }
          }
          .footer-oneTitle-title{
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #FFD69B;
            padding: 20rpx 0;
            .footer-oneTitle-msg-col{
              background: #FFD69B!important;
              padding: 0!important;
              border-bottom: none!important;
            }
          }
        }
        .guize-shuoming{
          padding-bottom: 20rpx;
          .footer-Title-title{
            font-size: 28rpx;
            font-family: PingFang SC-Medium, PingFang SC;
            font-weight: 500;
            color: #884D14;
          }
          .footer-Title-msg{
            font-size: 28rpx;
            font-family: PingFang SC-Medium, PingFang SC;
            font-weight: 500;
            color: #884D14;
          }
        }
      }
    }
  }
}


.zhankai {
  width: 100%;
  text-align: center;
  font-size: 26rpx;
  font-weight: 500;
  color: #999999;
  margin: 16rpx 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

/deep/ .u-countdown-time {
  padding: 6rpx;
}

.popup-show-box {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9;
}
.card-top{
  width: 100%;
  .coutdowm{
    width: 100%;
    padding: 30rpx;
    background: #F1F1F1;
    border-top-left-radius: 30rpx;
    border-top-right-radius: 30rpx;
  }
  .card-top-img{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 100rpx 0 60rpx;
    background: #FFFFFF;
    position: relative;
    .changetype{
      position: absolute;
      top: 20rpx;
      left: 20rpx;
      padding: 16rpx 20rpx;
      background: #F1F1F1;
      border-radius: 10rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      .changcontent{
        position: absolute;
        bottom: -220rpx;
        left: 0rpx;
        border-radius: 16rpx;
        .content-items{
          width: 182rpx;
          padding: 16rpx 20rpx;
          border-bottom: 2rpx solid #ccc;
          background:#F1F1F1;
          &:last-child{
            border-bottom: none;
          }
        }
      }
    }
    .card-tg-item {
      width: 100rpx;
      height: 100rpx;
      margin-right: 30rpx;
      will-change: transform;
      border-radius: 50%;
      .card-tg-items{
        width: 96rpx;
        height: 96rpx;
        border-radius: 50%;
      }
    }
    .card-tg-item-left{
      margin-right: 10rpx;
    }
    .tgActive {
      font-size: 28rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 500;
      border: 4rpx solid #EBC690;
      position: relative;
      &:after{
        position: absolute;
        content: '团长';
        width: 80rpx;
        height:40rpx;
        background: linear-gradient(135deg, #FEC983 0%, #FEE0B4 100%);
        color: #623808;
        top: -24rpx;
        left: 10rpx;
        border-radius: 20rpx;
        line-height: 40rpx;
      }
    }
  }
  .button_gos{
    background: #FFFFFF;
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 50rpx;
    .button_go{
      width: 88%;
      display: flex;
      justify-content: center;
      align-items: center;
      background: linear-gradient(104deg, #FE822A 0%, #FD6802 100%);
      color: #fff;
      padding: 18rpx;
      font-size: 32rpx;
      border-radius: 40rpx;
      height:76rpx;
      border: none;
    }
    .disabled{
      background: #999999;
      color: #fff;
    }
    .active{
      background: linear-gradient(104deg, #FE822A 0%, #FD6802 100%);
      color: #fff;
    }
  }
  .guize{
    border-top: 2rpx solid #F1F1F1;
    .footer-oneTitle {
      padding: 24rpx 36rpx;
      font-size: 28rpx;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #777777;
      display: flex;
      align-items: flex-start;
      background: #ffffff;
      &-title {
        width:80rpx;
        line-height: 1.8;
      }
      &-msg {
        padding-left: 45rpx;
        color: #333;
        line-height: 1.8;
      }
    }
  }
}



</style>
